package com.example.androidlearning;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;


import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.example.androidlearning.sy10.sy2sqlite.Sy1002_MainSQLite;
import com.example.androidlearning.sy10.sy1shared.Shared;
import com.example.androidlearning.sy11.Sy1101_ContentProvider;
import com.example.androidlearning.sy11.sy2dict.DictResolverActivity;
import com.example.androidlearning.sy12.sy1localservice.Sy1201_MainActivity;
import com.example.androidlearning.sy12.sy2musicplayer.MusicPlayerActivity;
import com.example.androidlearning.sy13.BroadcastActivity;
import com.example.androidlearning.sy14.LBSMainActivity;
import com.example.androidlearning.sy14.MapMainActivity;
import com.example.androidlearning.sy2.LinearLayoutActivity;
import com.example.androidlearning.sy2.RelativeLayoutActivity;
import com.example.androidlearning.sy2.TableLayoutActivity;
import com.example.androidlearning.sy3.ImageViewActivity;
import com.example.androidlearning.sy3.LoginViewActivity;
import com.example.androidlearning.sy4.ListView01;
import com.example.androidlearning.sy4.ListView02;
import com.example.androidlearning.sy5.sy5Activity01;
import com.example.androidlearning.sy5.sy5Activity02;
import com.example.androidlearning.sy5.sy5Activity03;
import com.example.androidlearning.sy6.Sy6Activity01;
import com.example.androidlearning.sy6.Sy6Activity02;
import com.example.androidlearning.sy7.Sy7Activity01;
import com.example.androidlearning.sy7.Sy7Activity02;
import com.example.androidlearning.sy8.Sy8Activity;
import com.example.androidlearning.sy9.Sy0901_Frame;
import com.example.androidlearning.sy9.Sy0902_Camera;
import com.example.androidlearning.sy9.Sy0902_Video;

import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

    private ExpandableListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
        setListeners();
    }

    void init(){
        listView = findViewById(R.id.listview);

        ArrayList<String> list = new ArrayList<>();
        list = getList(new String[]{
                "实验2",
                "实验3",
                "实验4",
                "实验5",
                "实验6",
                "实验7",
                "实验8",
                "实验9",
                "实验10",
                "实验11",
                "实验12",
                "实验13",
                "实验14",
        });
        ArrayList<ArrayList<String>> groupList = new ArrayList<>();

        groupList.add(getList(new String[]{"2.1", "2.2","2.3"}));
        groupList.add(getList(new String[]{"3.1","3.2"}));
        groupList.add(getList(new String[]{"4.1","4.2"}));
        groupList.add(getList(new String[]{"5.1","5.2"}));
        groupList.add(getList(new String[]{"6.1","6.2"}));
        groupList.add(getList(new String[]{"7.1","7.2"}));
        groupList.add(getList(new String[]{"8.1"}));
        groupList.add(getList(new String[]{"9.1","9.2","9.3"}));
        groupList.add(getList(new String[]{"10.1","10.2"}));
        groupList.add(getList(new String[]{"11.1","11.2"}));
        groupList.add(getList(new String[]{"12.1","12.2"}));
        groupList.add(getList(new String[]{"13.1"}));
        groupList.add(getList(new String[]{"14.1", "14.2"}));


        MyAdapter elv = new MyAdapter(this, list, groupList);

//        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, R.layout.listview_arry_item, lable);
        listView.setAdapter(elv);

    }

    private ArrayList<String> getList(String[] item){
        return new ArrayList<>(Arrays.asList(item));
    }

    void setListeners(){
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                        switch (groupPosition){
                            case 0:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, LinearLayoutActivity.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, RelativeLayoutActivity.class));
                                        break;
                                    case 2:
                                        startActivity(new Intent(MainActivity.this, TableLayoutActivity.class));
                                        break;
                                }
                                break;
                            case 1:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, LoginViewActivity.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, ImageViewActivity.class));
                                        break;
                                }
                            case 2:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, ListView01.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, ListView02.class));
                                        break;

                                }
                                break;
                            case 3:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, sy5Activity01.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, sy5Activity02.class));
                                        break;
                                    case 2:
                                        startActivity(new Intent(MainActivity.this, sy5Activity03.class));
                                        break;
                                }
                                break;
                            case 4:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy6Activity01.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, Sy6Activity02.class));
                                        break;
                                }
                                break;
                            case 5:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy7Activity01.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, Sy7Activity02.class));
                                        break;
                                }
                                break;
                            case 6:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy8Activity.class));
                                        break;
                                }
                                break;
                            case 7:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy0901_Frame.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, Sy0902_Video.class));
                                        break;
                                    case 2:
                                        startActivity(new Intent(MainActivity.this, Sy0902_Camera.class));
                                        break;

                                }
                                break;
                            case 8:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Shared.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, Sy1002_MainSQLite.class));
                                        break;

                                }
                                break;
                            case 9:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy1101_ContentProvider.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, DictResolverActivity.class));
                                        break;
                                }
                                break;
                            case 10:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, Sy1201_MainActivity.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, MusicPlayerActivity.class));
                                        break;
                                }
                                break;
                            case 11:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, BroadcastActivity.class));
                                        break;
                                }
                            case 12:
                                switch (childPosition){
                                    case 0:
                                        startActivity(new Intent(MainActivity.this, LBSMainActivity.class));
                                        break;
                                    case 1:
                                        startActivity(new Intent(MainActivity.this, MapMainActivity.class));
                                        break;
                                }
                        }
                return true;
            }
        });

    }

}
